<template>
	<view class="memberSalesRecord">
		<headerVue ref="header" :query="shopInfo" @toggle="toggle"  @changeIndex="changeHeaderIndex" @dateConfirm="dateConfirm"></headerVue>
		</headerVue>
		<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="scrolltolower">
			<view class="comlumn_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="Item">
					<view class="top">
						<view class="user">
							<image :src="item.user_info.avatar" mode="" class="uimg"></image>
							<view class="name">
								{{item.user_info.nickname}}
							</view>
						</view>
						<view class="time">
							{{item.time}}
						</view>
					</view>
					<view class="bottom">
						<image :src="item.course_info.image" mode="aspectFill" class="memberCard"></image>
						<view class="right-box">
							 <view class="right_top">
							 	<view class="title1">
							 		{{item.course_info.title}}
							 	</view>
								<view class="red_box">
									<view class="unit">
										￥
									</view>
									<view class="price">
										{{item.cost}}
									</view>
								</view>
							 </view>
							 <view class="top2">
							 	<view class="top_left">
							 		
							 	</view>
								<view class="size3">
									{{item.that_str}}
								</view>
							 </view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="'课程销售记录'"></empty>
		</scroll-view>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
	</view>
</template>

<script>
	import headerVue from './components/header.vue'
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import empty from './components/empty.vue'
	import{
		atShop,
		storefinanceCourse
	} from '@/api/manager.js'
	export default {
		components: {
			headerVue,
			FieldPopupVue,
			empty
		},
		data() {
			return {
				query:{
					date:'',
					form:'day',
					shop_id:'',
					page:1
				},
				// 切换门店
				popupShow: false,
				shopInfo:{},
				Field: [],
				FieldIndex: -1,
				popupShow: false,
				list:[],
				status: 'loadmore', //当前状态
			}
		},
		mounted() {
			this.query.date = this.$refs.header.day
			this.getatShop()
			this.getstorefinanceCard()
		},
		methods: {
			scrolltolower(){
				this.query.page++
				this.getstorefinanceCard()
			},
			getstorefinanceCard(){
				storefinanceCourse(this.query).then(({data:res})=>{
					console.log('res', res);
					if (res.code == 1) {
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}
					
						console.log('list', this.list);
					}
				})
			},
			getatShop(e){
				atShop(e).then(({data:res})=>{
					if(res.code == 1){
						this.shopInfo = res.data
						console.log('res', this.shop_info);
					}
				})
			},
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			dateConfirm(e, data){
				console.log('e321', data);
				this.query.date = data
				this.list = []
				this.query.page = 1
				this.getstorefinanceCard()
			},
			changeHeaderIndex(e){
				this.query.form = e == 0 ? 'day' : e == 1 ? 'month' : 'year'
				this.query.date = this.$refs.header.day
				this.list = []
				this.query.page = 1
				this.getstorefinanceCard()
			},
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.query.shop_id = item.shop_id
				this.getatShop({
					shop_id: item.shop_id
				})
				this.getstorefinanceCard()
			},
			sure() {
				this.popupShow = false
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.memberSalesRecord {
		display: flex;
		flex-direction: column;
		align-items: center;

		.tab {
			width: 750rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			background: #ffffff;

			.tabIndex {
				display: flex;
				flex-direction: column;
				align-items: center;

				.tabsize1 {
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Heavy;
					font-weight: 800;
					text-align: center;
					color: #73F0EA;
					letter-spacing: 0.7rpx;

				}

				.tabsize2 {
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					text-align: center;
					color: #666666;
					letter-spacing: 0.7rpx;

				}

				.active {
					margin-top: 12rpx;
					width: 44rpx;
					height: 8rpx;

					.empty {
						width: 100%;
						height: 100%;
						background: #73F0EA;
						border: 2rpx solid rgba(0, 0, 0, 0.00);
						border-radius: 2rpx;
					}
				}
			}
		}
		.scroll-Y{
			width: 100%;
			height: 80vh;
			.comlumn_box{
				display: flex;
				flex-direction: column;
				align-items: center;
				padding-top: 20rpx;
				.Item{
					width: 702rpx;
					height: 256rpx;
					background: #ffffff;
					border-radius: 16rpx;
					padding: 20rpx 24rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					margin-bottom: 20rpx;
					.top{
						width: 100%;
						padding-bottom: 22rpx;
						display: flex;
						flex-direction: row;
						align-items: center;
						.user{
							flex: 1;
							display: flex;
							flex-direction: row;
							align-items: center;
							.uimg{
								width: 48rpx;
								height: 48rpx;
								background: #f6f6f6;
								border-radius: 50%;
								margin-right: 14rpx;
							}
							.name{
								font-size: 28rpx;
								font-family: PingFang SC, PingFang SC-Bold;
								font-weight: 700;
								text-align: left;
								color: #333333;
							}
						}
						.time{
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC-Medium;
							font-weight: 500;
							color: #999999;
						}
					}
					.bottom{
						padding-top: 26rpx;
						display: flex;
						flex-direction: row;
						width: 100%;
						.memberCard{
							width: 160rpx;
							height: 120rpx;
							margin-right: 20rpx;
						}
						.right-box{
							display: flex;
							flex-direction: column;
							flex: 1;
							.right_top{
								display: flex;
								flex-direction: row;
								align-items: center;
								margin-bottom: 8rpx;
								.title1{
									font-size: 32rpx;
									font-family: PingFang SC, PingFang SC-Bold;
									font-weight: 700;
									text-align: left;
									color: #333333;
									flex: 1;
								}
								.red_box{
									display: flex;
									flex-direction: row;
									align-items: baseline;
									.unit{
										font-size: 24rpx;
										font-family: PingFang SC, PingFang SC-Bold;
										font-weight: 700;	
										color: #f37364;
									}
									.price{
										font-size: 32rpx;
										font-family: DIN, DIN-Bold;
										font-weight: 700;
										text-align: left;
										color: #f37364;
									}
								}
							}
							.top2{
								display: flex;
								flex-direction: row;
								align-items: center;
								.top_left{
									flex: 1;
								}
								.size3{
									font-size: 24rpx;
									font-family: PingFang SC, PingFang SC-Regular;
									font-weight: 400;
									color: #666666;
								}
							}
						}
					}
				}
			}
		}
	}
</style>